package deviceinfo.wsm.com.deviceinfo.screen;

import android.content.Context;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

import java.util.LinkedHashMap;

import deviceinfo.wsm.com.deviceinfo.WsmDeviceInfoSDK;

/**
 * Created by 王家宝 on 2018/7/6.
 * TEL:18241150668
 * MAIL:639586819@qq.com
 */

public class ScreenInfoUtils {

    /**
     * 获取屏幕正常分辨率
     */
    private static String getResolution() {
        WindowManager wm = (WindowManager) WsmDeviceInfoSDK.getWsmSDK().getAppContext().
                getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        int screenHeight = display.getHeight();
        int screenWidth = display.getWidth();
        return screenWidth + " * " + screenHeight;
    }

    private static int getRealResolutionWidth() {
        DisplayMetrics metrics = new DisplayMetrics();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            ((WindowManager) WsmDeviceInfoSDK.getWsmSDK().getAppContext().
                    getSystemService(Context.WINDOW_SERVICE))
                    .getDefaultDisplay().getRealMetrics(metrics);
        }
        return metrics.widthPixels;
    }

    private static int getRealResolutionHeight() {
        DisplayMetrics metrics = new DisplayMetrics();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            ((WindowManager) WsmDeviceInfoSDK.getWsmSDK().getAppContext().
                    getSystemService(Context.WINDOW_SERVICE))
                    .getDefaultDisplay().getRealMetrics(metrics);
        }
        return metrics.heightPixels;
    }

    private static int getDensityDpi() {
        DisplayMetrics metrics = WsmDeviceInfoSDK.getWsmSDK().getAppContext().
                getResources().getDisplayMetrics();
        return metrics.densityDpi;
    }

    public static LinkedHashMap<String, String> getAll() {
        LinkedHashMap<String, String> data = new LinkedHashMap<>();
        data.put("屏幕分辨率", getResolution());
        data.put("屏幕密度", getDensityDpi() + "");
        data.put("屏幕宽度", getRealResolutionWidth() + "");
        data.put("屏幕高度", getRealResolutionHeight() + "");
        return data;
    }
}
